<template>
  <div>
    <van-list
      v-model="loading"
      :finished="finished"
      finished-text="没有更多了"
      @load="onLoad"
    >
      <comment-item @click-reply="$emit('click-reply',$event)" :comment="item" v-for="item in list" :key="item.com_id + ''" />
      <!-- <van-cell v-for="item in list" :key="item.com_id + ''" :title="item.content" /> -->
    </van-list>
  </div>
</template>

<script>
import { getCommentList } from '@/api/article.js'
import CommentItem from '../../../components/CommentItem.vue'

export default {
  components: { CommentItem },
  props: {
    type: {
      type: String,
      default: 'a'
    },
    source: {
      type: [Number, Object, String],
      required: true
    },
    list: {
      type: Array,
      default: () => []
    }
  },
  data () {
    return {
      loading: false,
      finished: false,
      offset: null,
      limit: 10
    }
  },

  created () {},

  methods: {
    async onLoad () {
      // 1.获取数据
      try {
        const res = await getCommentList({
          type: this.type,
          source: this.source,
          offset: this.offset,
          limit: this.limit
        })
        // console.log(res)
        this.$emit('getTotalCount', res.total_count)
        this.list.push(...res.results)
        this.loading = false
        if (!res.results.length) {
          this.finished = true
        } else {
          this.offset = res.last_id
        }
      } catch (err) {

      }
    }
  }
}
</script>

<style scoped lang="less"></style>
